//
//  MineViewController.m
//  Everest
//
//  Created by 李其昌 on 14/12/17.
//  Copyright (c) 2014年 ThreeL. All rights reserved.
//

#import "MineViewController.h"
#import "LogInViewController.h"
#import "SDImageCache.h"
#import "MineCell.h"
#import "NetHandler.h"
#import "UIImageView+AFNetworking.h"
#import "Mine.h"
#import "WeiboSDK.h"
#import "AppDelegate.h"
#import "AboutViewController.h"
#import "CollectViewController.h"
#import "DataBaseHandler.h"


#define APPKEY @"3856338914"
#define REDIRECTURI @"http://www.sharesdk.cn"
#define kMax 5

@interface MineViewController ()<WBHttpRequestDelegate, UIAlertViewDelegate>

@property (nonatomic,retain) UIView *nigView;
@property (nonatomic,retain) UILabel *attenNum;
@property (nonatomic,retain) UILabel *beanNum;
@property (nonatomic,retain) UILabel *wbNum;
@property (nonatomic,retain) UILabel *nameLabel;
@property (nonatomic,retain) UIImageView *NameImage;
@property (nonatomic,retain) Mine *mine;
@property (nonatomic,retain) NSString *Judgement;
@property (nonatomic,retain) UIStepper *stepper;
@property (nonatomic,assign) NSInteger value;
@property (nonatomic,retain) UILabel *showLabel;
@property (nonatomic, retain) NSMutableArray *arr;

@end

@implementation MineViewController

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    
    if (self) {
        
        self.value = kMax;
        
        NSNotificationCenter *fication = [NSNotificationCenter defaultCenter];
        
        [fication addObserver:self selector:@selector(receiveNotifica:) name:@"login" object:nil];
        
    }
    return self;
}

- (void)receiveNotifica:(NSNotification *)fication
{
    self.Judgement = @"YES";
    
    UIView *view = (UIView *)[self.view viewWithTag:100];
    UIView *view2 = (UIView *)[self.view viewWithTag:102];
    view.hidden = YES;
    view2.hidden = NO;
    
//    NSLog(@"%@", fication.userInfo);
    
    NSString *str = [fication.userInfo objectForKey:@"access_token"];
    NSNumber *number = [fication.userInfo objectForKey:@"uid"];
    
//    NSLog(@"%@", str);
//    NSLog(@"%@", number);
    
    NSString *meshStr = [NSString stringWithFormat:@"https://api.weibo.com/2/users/show.json?uid=%@&access_token=%@", [number description], str];
    
    [NetHandler getDataWithUrl:meshStr completion:^(NSData *data) {
        
        NSDictionary *resultDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
//        NSLog(@"%@", resultDic);
        self.mine = [[Mine alloc] initWithDictionary:resultDic];
        
        NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
        [userDefault setObject:@"YES" forKey:@"isLogin"];
        [userDefault setObject:self.mine.uid forKey:@"uid"];
        [userDefault synchronize];
        
        self.nameLabel.text = self.mine.screen_name;
//        NSLog(@"%@", self.mine.screen_name);
        self.attenNum.text = [self.mine.friends_count description];
        self.beanNum.text = [self.mine.followers_count description];
        self.wbNum.text = [self.mine.statuses_count description];
        [self.NameImage setImageWithURL:[NSURL URLWithString:self.mine.avatar_hd]];
        [_mine release];
    }];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"注销" style:UIBarButtonItemStylePlain target:self action:@selector(barAction:)];
    
//    NSMutableDictionary *dic = [fication.userInfo objectForKey:@"key"];
//    
//    self.nameLabel.text = [dic objectForKey:@"name"];
//    
//    NSURL *url = [NSURL URLWithString:[dic objectForKey:@"profile_image_url"]];
//    [self.NameImage setImageWithURL:url];
//    
//    
//    NSNumber *att = [dic objectForKey:@"friends_count"];
//    NSNumber *bean = [dic objectForKey:@"friends_count"];
//    NSNumber *wb = [dic objectForKey:@"statuses_count"];
//    
//    
//    self.attenNum.text = [att description];
//    self.beanNum.text = [bean description];
//    self.wbNum.text = [wb description];

}

- (void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBar.translucent = YES;
}

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [_showLabel release];
    [_stepper release];
    [_nameLabel release];
    [_mine release];
    [_NameImage release];
    [_wbNum release];
    [_beanNum release];
    [_attenNum release];
    [_nigView release];
    [_arr release];
    [super dealloc];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor colorWithRed:240 / 255.0 green:255 / 255.0 blue:255 / 255.0 alpha:1.0];
    self.navigationController.navigationBar.translucent = YES;

    self.navigationItem.title = @"个人中心";
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"注销" style:UIBarButtonItemStylePlain target:self action:@selector(barAction:)];
    self.navigationItem.rightBarButtonItem = nil;
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"分享" style:UIBarButtonItemStylePlain target:self action:@selector(leftBarAction:)];
    
    UIView *bossView = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height *9.5 / 100, self.view.bounds.size.width, self.view.bounds.size.height * 32 / 100)];
    bossView.tag = 100;
    [self.view addSubview:bossView];
    [bossView release];
    
    UIImageView * boss1Image = [[UIImageView alloc] initWithFrame:bossView.bounds];
    UIImage *boimage = [UIImage imageNamed:@"3.jpg"];
    boss1Image.image = boimage;
    boss1Image.backgroundColor = [UIColor redColor];
    [bossView addSubview:boss1Image];
    [boss1Image release];
    
    //    UIImageView * nameImage = [[UIImageView alloc] initWithFrame:bossView.bounds];
    //    nameImage.backgroundColor = [UIColor redColor];
    //    nameImage.image = boimage;
    //    [nameView addSubview:bossImage];
    //    [nameImage release];
    
    
    UIImageView *userImage = [[UIImageView alloc] initWithFrame:CGRectMake(bossView.bounds.size.width * 2 / 5, bossView.bounds.size.height / 4, bossView.bounds.size.width * 19 / 100, bossView.bounds.size.height * 35 / 100)];
    userImage.backgroundColor = [UIColor whiteColor];
    UIImage *usimage = [UIImage imageNamed:@"sina.png"];
    
//    userImage.backgroundColor = [UIColor huiseColor];
    userImage.layer.cornerRadius = userImage.frame.size.height / 2;
    [bossView addSubview:userImage];
    [userImage release];
    
    UIImageView *sImage = [[UIImageView alloc] initWithFrame:CGRectMake(userImage.bounds.size.width * 5.7 / 100, userImage.bounds.size.height * 5.7 / 100, userImage.bounds.size.width - (userImage.bounds.size.width * 11.4 /100), userImage.bounds.size.height - (userImage.bounds.size.height * 11.4 /100))];
    sImage.backgroundColor = [UIColor whiteColor];
    sImage.layer.cornerRadius = (userImage.bounds.size.height - (userImage.bounds.size.height * 11.4 /100)) / 2;
    
    UIImageView *myUserImage = [[UIImageView alloc] initWithFrame:CGRectMake(sImage.bounds.size.width *15 / 100, sImage.bounds.size.height * 11.2 / 100, sImage.bounds.size.width - (sImage.bounds.size.width * 32.2 / 100), sImage.bounds.size.height - (sImage.bounds.size.height * 32.2 / 100))];
    [sImage addSubview:myUserImage];
    myUserImage.image = usimage;
    myUserImage.layer.cornerRadius = (sImage.bounds.size.height - (sImage.bounds.size.height * 32.2 / 100))/2;
    [myUserImage release];
    [userImage addSubview:sImage];
    [sImage release];
    
    UITapGestureRecognizer *tapOne = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapOneAction:)];
    [bossView addGestureRecognizer:tapOne];
    [tapOne release];
    //=============================================
    UIView *nameView = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height *9.5 / 100, self.view.bounds.size.width, self.view.bounds.size.height * 32 / 100)];
    nameView.tag = 102;
    [self.view addSubview:nameView];
    [nameView release];
    
    UIImageView * nameImage = [[UIImageView alloc] initWithFrame:bossView.bounds];
    nameImage.backgroundColor = [UIColor redColor];
    nameImage.image = boimage;
    [nameView addSubview:nameImage];
    [nameImage release];
    
    
    UIImageView *oneImage = [[UIImageView alloc] initWithFrame:CGRectMake(nameView.bounds.size.width * 2 / 5, nameView.bounds.size.height / 8, nameView.bounds.size.width * 18 / 100, nameView.bounds.size.height * 32.5 / 100)];
//    oneImage.backgroundColor = [UIColor huiseColor];
    oneImage.layer.cornerRadius = oneImage.frame.size.width / 2;
    [nameView addSubview:oneImage];
    [oneImage release];
    
    
    UIImageView *akbImage = [[UIImageView alloc] initWithFrame:CGRectMake(oneImage.bounds.size.width * 5.7 / 100, oneImage.bounds.size.height * 5.7 / 100, oneImage.bounds.size.width - (oneImage.bounds.size.width * 11.4 /100), oneImage.bounds.size.height - (oneImage.bounds.size.height * 11.4 /100))];
    akbImage.backgroundColor = [UIColor whiteColor];
    akbImage.layer.cornerRadius = (oneImage.bounds.size.height - (oneImage.bounds.size.height * 11.4 /100)) / 2;
    [oneImage addSubview:akbImage];
    [akbImage release];
    
    //
    self.NameImage = [[UIImageView alloc] initWithFrame:CGRectMake(oneImage.bounds.size.width * 5.7 / 100, oneImage.bounds.size.height * 5.7 / 100, oneImage.bounds.size.width - (oneImage.bounds.size.width * 11.4 /100), oneImage.bounds.size.height - (oneImage.bounds.size.height * 11.4 /100))];
    [oneImage addSubview:self.NameImage];
    self.NameImage.layer.cornerRadius = (oneImage.bounds.size.height - (oneImage.bounds.size.height * 11.4 /100)) / 2;
    
    self.NameImage.clipsToBounds = YES;
    [_NameImage release];
    
    
    self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(nameView.bounds.size.width * 11 / 100, nameView.bounds.size.height * 6.5 / 14, nameView.bounds.size.width * 73.33 / 100, nameView.bounds.size.height * 13.95 / 100)];
    
    self.nameLabel.textAlignment = 1;
    //nameLabel.backgroundColor = [UIColor redColor];
    [nameView addSubview:self.nameLabel];
    [_nameLabel release];
    
    UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(nameView.bounds.size.width * 36.53 / 100, nameView.bounds.size.height * 6.5 / 10, 1, nameView.bounds.size.height *2.5 / 11)];
//    view1.backgroundColor = [UIColor shenhuiseColor];
    [nameView addSubview:view1];
    
    UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(nameView.bounds.size.width * 64 / 100, nameView.bounds.size.height * 6.5 / 10, 1, nameView.bounds.size.height *2.5 / 11)];
//    view2.backgroundColor = [UIColor shenhuiseColor];
    [nameView addSubview:view2];
    
    UILabel *attenLabel = [[UILabel alloc] initWithFrame:CGRectMake(nameView.bounds.size.width *19 / 100, nameView.bounds.size.height * 7.65 / 10, nameView.bounds.size.width * 13.33 / 100, nameView.bounds.size.height * 11.62 / 100)];
    attenLabel.text = @"关注";
    //attenLabel.backgroundColor = [UIColor redColor];
    attenLabel.textAlignment = 1;
    [nameView addSubview:attenLabel];
    [attenLabel release];
    
    
    UILabel *beanLabel = [[UILabel alloc] initWithFrame:CGRectMake(nameView.bounds.size.width *43.33 / 100, nameView.bounds.size.height * 7.65 / 10, nameView.bounds.size.width * 13.33 / 100, nameView.bounds.size.height * 11.62 / 100)];
    beanLabel.text = @"粉丝";
    beanLabel.textAlignment = 1;
    beanLabel.font = [UIFont systemFontOfSize:16];
    [nameView addSubview:beanLabel];
    [beanLabel release];
    
    UILabel *wbLabel = [[UILabel alloc] initWithFrame:CGRectMake(nameView.bounds.size.width *69 / 100, nameView.bounds.size.height * 7.65 / 10, nameView.bounds.size.width * 13.33 / 100, nameView.bounds.size.height * 11.62 / 100)];
    wbLabel.text = @"微博";
    wbLabel.textAlignment = 1;
    wbLabel.font = [UIFont systemFontOfSize:16];
    [nameView addSubview:wbLabel];
    [wbLabel release];
    
    
    self.attenNum = [[UILabel alloc] initWithFrame:CGRectMake(nameView.bounds.size.width *19 / 100, nameView.bounds.size.height * 6.5 / 10, nameView.bounds.size.width * 13.33 / 100, nameView.bounds.size.height * 11.62 / 100)];
    self.attenNum.textAlignment = 1;
    
    [nameView addSubview:self.attenNum];
    [_attenNum release];
    
    self.beanNum = [[UILabel alloc] initWithFrame:CGRectMake(nameView.bounds.size.width *43.33 / 100, nameView.bounds.size.height * 6.5 / 10, nameView.bounds.size.width * 13.33 / 100, nameView.bounds.size.height * 11.62 / 100)];
    self.beanNum.textAlignment = 1;
    
    [nameView addSubview:self.beanNum];
    [_beanNum release];
    
    
    self.wbNum = [[UILabel alloc] initWithFrame:CGRectMake(nameView.bounds.size.width * 69 / 100, nameView.bounds.size.height * 6.5 / 10, nameView.bounds.size.width * 13.33 / 100, nameView.bounds.size.height * 11.62 / 100)];
    self.wbNum.textAlignment = 1;
    
    [nameView addSubview:self.wbNum];
    [_wbNum release];
    
    nameView.hidden = YES;
    
    
    //=================================================
    //登入状态
    UILabel *ennerLabel = [[UILabel alloc] initWithFrame:CGRectMake(bossView.bounds.size.width * 26.6 / 100, bossView.bounds.size.height * 60.4 / 100, bossView.bounds.size.width * 46.6 / 100, bossView.bounds.size.height * 11.6 / 100)];
    ennerLabel.text = @"新浪微博登陆";
    ennerLabel.textAlignment = 1;
    ennerLabel.font = [UIFont systemFontOfSize:16];
    [bossView addSubview:ennerLabel];
    [ennerLabel release];
    
    //============================================
    //我的收藏
    UIView *collectView = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height * 43.5 / 100, self.view.bounds.size.width, self.view.bounds.size.height * 7.49 / 100)];
    collectView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:collectView];
    [collectView release];
    
    UITapGestureRecognizer *collectTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(collextTap:)];
    [collectView addGestureRecognizer:collectTap];
    [collectTap release];
    
    UIImageView *collectImage = [[UIImageView alloc] initWithFrame:CGRectMake(collectView.bounds.size.width * 5.33 / 100, collectView.bounds.size.height * 3 / 11, collectView.bounds.size.width * 6.66 / 100, collectView.bounds.size.height  / 2)];
    UIImage *collImage = [UIImage imageNamed:@"shoucan.png"];
    collectImage.image = collImage;
    [collectView addSubview:collectImage];
    [collectImage release];
    
    UILabel *collectLabel = [[UILabel alloc] initWithFrame:CGRectMake(collectView.bounds.size.width * 18.6 / 100, collectView.bounds.size.height / 5, collectView.bounds.size.width * 20 / 100, collectView.bounds.size.height * 3 /5)];
    collectLabel.text = @"最近收藏";
    collectLabel.font = [UIFont systemFontOfSize:16];
    [collectView addSubview:collectLabel];
    [collectLabel release];
    
    UIImageView *imageCollect = [[UIImageView alloc] initWithFrame:CGRectMake(collectView.bounds.size.width * 90.6 / 100, collectView.bounds.size.height * 3 / 10, collectView.bounds.size.width / 25, collectView.bounds.size.height * 44 / 100)];
    UIImage *rightImage = [UIImage imageNamed:@"xiangyou.png"];
    imageCollect.image = rightImage;
    [collectView addSubview:imageCollect];
    
    //============================================
    //下载设置
    UIView *browseView = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height * 51.32 / 100, self.view.bounds.size.width, self.view.bounds.size.height * 7.49 / 100)];
    browseView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:browseView];
    [browseView release];
    
    UIImageView *browseImage = [[UIImageView alloc] initWithFrame:CGRectMake(collectView.bounds.size.width * 5.33 / 100, collectView.bounds.size.height * 3 / 11, collectView.bounds.size.width * 6.66 / 100, collectView.bounds.size.height  / 2)];
    UIImage *browImage = [UIImage imageNamed:@"xiazai.png"];
    browseImage.image = browImage;
    [browseView addSubview:browseImage];
    [browseImage release];
    
    UILabel *browseLabel = [[UILabel alloc] initWithFrame:CGRectMake(collectView.bounds.size.width * 18.6 / 100, collectView.bounds.size.height / 5, collectView.bounds.size.width * 35 / 100, collectView.bounds.size.height * 3 /5)];
    browseLabel.text = @"同时下载数为";
    browseLabel.font = [UIFont systemFontOfSize:16];
    [browseView addSubview:browseLabel];
    [browseLabel release];
    
    self.showLabel = [[UILabel alloc] initWithFrame:CGRectMake(collectView.bounds.size.width * 18.6 / 100 + collectView.bounds.size.width * 30 / 100, collectView.bounds.size.height / 5, collectView.bounds.size.width * 10 / 100, collectView.bounds.size.height * 3 / 5)];
    NSNumber *number = [NSNumber numberWithInteger:self.value];
    self.showLabel.text = [number description];
    [browseView addSubview:self.showLabel];
    [_showLabel release];
    
    UIButton *addButton = [UIButton buttonWithType:UIButtonTypeSystem];
    addButton.frame = CGRectMake(collectView.bounds.size.width * 80 / 100, browseView.bounds.size.height / 7, collectView.bounds.size.width / 11, browseView.bounds.size.height - browseView.bounds.size.height / 5);
    addButton.tintColor = [UIColor redColor];
    addButton.titleLabel.font = [UIFont systemFontOfSize:24];
    [addButton setTitle:@"-" forState:UIControlStateNormal];
    [addButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
    [browseView addSubview:addButton];
    
    UIButton *subButton = [UIButton buttonWithType:UIButtonTypeSystem];
    subButton.frame = CGRectMake(collectView.bounds.size.width * 80 / 100 + collectView.bounds.size.width / 11, browseView.bounds.size.height / 7.5, collectView.bounds.size.width / 11, browseView.bounds.size.height - browseView.bounds.size.height / 5);
    subButton.titleLabel.font = [UIFont systemFontOfSize:24];
    subButton.tintColor = [UIColor redColor];
    [subButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
    [subButton setTitle:@"+" forState:UIControlStateNormal];
    [browseView addSubview:subButton];
    
//    self.value = [[[NSUserDefaults standardUserDefaults] valueForKey:@"kMaxRequestCount"] integerValue];
//    NSLog(@"%ld",self.value);
//    self.stepper = [[UIStepper alloc] init];
////    self.stepper.frame = CGRectMake(collectView.bounds.size.width * 83 / 100, browseView.bounds.size.height / 7, 1, 1);
//    self.stepper.backgroundColor = [UIColor whiteColor];
//    [browseView addSubview:self.stepper];
//    [_stepper release];
    
//    UITapGestureRecognizer *browseTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(browseTapAction:)];
//    [browseView addGestureRecognizer:browseTap];
//    [browseTap release];
    
//    UIImageView *imageBrowse = [[UIImageView alloc] initWithFrame:CGRectMake(collectView.bounds.size.width * 90.6 / 100, collectView.bounds.size.height * 3 / 10, collectView.bounds.size.width / 25, collectView.bounds.size.height * 44 / 100)];
//    imageBrowse.image = rightImage;
//    [browseView addSubview:imageBrowse];
    
    
    //夜间模式
    UIView *hightView = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height * 60.8 / 100, self.view.bounds.size.width, self.view.bounds.size.height * 7.49 / 100)];
    hightView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:hightView];
    [hightView release];
    
    UIImageView *hightImage = [[UIImageView alloc] initWithFrame:CGRectMake(collectView.bounds.size.width * 5.33 / 100, collectView.bounds.size.height * 3 / 10, collectView.bounds.size.width * 6 / 100, collectView.bounds.size.height  / 2 - 2)];
    UIImage *higImage = [UIImage imageNamed:@"yejian.png"];
    hightImage.image = higImage;
    [hightView addSubview:hightImage];
    [hightImage release];
    
    UILabel *hightLabel = [[UILabel alloc] initWithFrame:CGRectMake(collectView.bounds.size.width * 18.6 / 100, collectView.bounds.size.height / 6, collectView.bounds.size.width * 20 / 100, collectView.bounds.size.height * 3 /5)];
    hightLabel.text = @"夜间模式";
    hightLabel.font = [UIFont systemFontOfSize:16];
    [hightView addSubview:hightLabel];
    [hightLabel release];
    
    UISwitch *Switch = [[UISwitch alloc] initWithFrame:CGRectMake(collectView.bounds.size.width * 83 / 100, collectView.bounds.size.height / 7, collectView.bounds.size.width / 22, collectView.bounds.size.height  / 2)];
//    Switch.onTintColor = [UIColor hongse];
    [hightView addSubview:Switch];
    Switch.on = YES;
    [Switch setOn:NO];
    [Switch addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];
    
    [Switch release];
    
    
    //============================================
    
    
    //设置
    UIView *setView = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height * 70.3 / 100, self.view.bounds.size.width, self.view.bounds.size.height * 7.49 / 100)];
    setView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:setView];
    [setView release];
    
    UIImageView *setImage = [[UIImageView alloc] initWithFrame:CGRectMake(collectView.bounds.size.width * 5.33 / 100, collectView.bounds.size.height * 3 / 11, collectView.bounds.size.width * 6 / 100, collectView.bounds.size.height  / 2 - 2)];
    UIImage *seImage = [UIImage imageNamed:@"huancun.png"];
    setImage.image = seImage;
    [setView addSubview:setImage];
    [setImage release];
    
    UILabel *setLabel = [[UILabel alloc] initWithFrame:CGRectMake(collectView.bounds.size.width * 18.6 / 100, collectView.bounds.size.height / 5, collectView.bounds.size.width * 20 / 100, collectView.bounds.size.height * 3 /5)];
    setLabel.text = @"清除缓存";
    setLabel.font = [UIFont systemFontOfSize:16];
    [setView addSubview:setLabel];
    [setLabel release];
    
    UIImageView *imageSet = [[UIImageView alloc] initWithFrame:CGRectMake(collectView.bounds.size.width * 90.6 / 100, collectView.bounds.size.height * 3 / 10, collectView.bounds.size.width / 25, collectView.bounds.size.height * 44 / 100)];
    imageSet.image = rightImage;
    [setView addSubview:imageSet];
    
    UITapGestureRecognizer * tapSet = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapSetAction:)];
    [setView addGestureRecognizer:tapSet];
    [tapSet release];
    
    
    
    
    //============================================
    //关于我们
    UIView *regardView = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height * 79.8 / 100, self.view.bounds.size.width, self.view.bounds.size.height * 7.49 / 100)];
    regardView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:regardView];
    [regardView release];
    
    UIImageView *regardImage = [[UIImageView alloc] initWithFrame:CGRectMake(collectView.bounds.size.width * 5.33 / 100, collectView.bounds.size.height * 3 / 11, collectView.bounds.size.width * 6.66 / 100, collectView.bounds.size.height  / 2)];
    UIImage *regaImage = [UIImage imageNamed:@"guanyu.png"];
    regardImage.image = regaImage;
    [regardView addSubview:regardImage];
    [regardImage release];
    
    UILabel *regardLabel = [[UILabel alloc] initWithFrame:CGRectMake(collectView.bounds.size.width * 18.6 / 100, collectView.bounds.size.height / 5, collectView.bounds.size.width * 20 / 100, collectView.bounds.size.height * 3 /5)];
    regardLabel.text = @"关于我们";
    regardLabel.font = [UIFont systemFontOfSize:16];
    [regardView addSubview:regardLabel];
    [regardLabel release];
    
    UIImageView *imageRegard = [[UIImageView alloc] initWithFrame:CGRectMake(collectView.bounds.size.width * 90.6 / 100, collectView.bounds.size.height * 3 / 10, collectView.bounds.size.width / 25, collectView.bounds.size.height * 44 / 100)];
    imageRegard.image = rightImage;
    [regardView addSubview:imageRegard];
    
    UITapGestureRecognizer *tapAbout = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAboutAction:)];
    [regardView addGestureRecognizer:tapAbout];
    [tapAbout release];
    
    self.nigView = [[UIView alloc] initWithFrame:self.view.bounds];
    self.nigView.userInteractionEnabled = NO;
    self.nigView.hidden = YES;
    self.nigView.backgroundColor = [UIColor blackColor];
    self.nigView.alpha = 0.5;
    [self.tabBarController.view addSubview:self.nigView];
    [_nigView release];
    
}
// 登录页面跳转
- (void)tapOneAction:(UITapGestureRecognizer *)tap
{
    
    WBAuthorizeRequest *request = [WBAuthorizeRequest request];
    request.redirectURI = REDIRECTURI;
    request.scope = @"all";
    request.userInfo = @{@"SSO_From": @"MianViewController",
                         @"Other_Info_1": [NSNumber numberWithInt:123],
                         @"Other_Info_2": @[@"obj1", @"obj2"],
                         @"Other_Info_3": @{@"key1": @"obj1", @"key2": @"obj2"}};
    [WeiboSDK sendRequest:request];
    
}

- (void)tapAboutAction:(UITapGestureRecognizer *)tap
{
    
    AboutViewController *aboutVC = [[AboutViewController alloc] init];
    
    [self.navigationController pushViewController:aboutVC animated:YES];
    
    [aboutVC release];
    
}

// 下载设置按钮
- (void)buttonClicked:(UIButton *)button
{
//    NSLog(@"%@", button.titleLabel.text);
    
    if ([button.titleLabel.text isEqualToString:@"+"]) {
        
        if (self.value == 5) {
            
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"最大数为5" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
            [alertView show];
            [alertView release];
        } else {
        
        self.value += 1;
        
        NSNumber *number = [NSNumber numberWithInteger:self.value];
        self.showLabel.text = [number description];
        [[NSUserDefaults standardUserDefaults] setValue:number forKey:@"kMaxRequestCount"];
        [[NSUserDefaults standardUserDefaults] synchronize];
        }
        
    }else if ([button.titleLabel.text isEqualToString:@"-"]){
        
        if (self.value == 1) {
            
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"最小数为1" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
            [alertView show];
            [alertView release];
            
        } else {
        
            self.value -= 1;
            
            NSNumber *number = [NSNumber numberWithInteger:self.value];
            self.showLabel.text = [number description];
            [[NSUserDefaults standardUserDefaults] setValue:number forKey:@"kMaxRequestCount"];
            [[NSUserDefaults standardUserDefaults] synchronize];
        
        }
    }
    NSLog(@"%ld", self.value);
    
}

//- (void)browseTapAction:(UITapGestureRecognizer *)tap
//{
//    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"暂无" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
//    [alertView show];
//    [alertView release];
//}

// 最近收藏
- (void)collextTap:(UITapGestureRecognizer *)tap
{
    if ([self.Judgement isEqualToString:@"YES"]) {
        
        CollectViewController *collectVC = [[CollectViewController alloc] init];
        
        [self.navigationController pushViewController:collectVC animated:YES];
        
        [collectVC release];
        
    } else {
        
        
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"请登录" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
        [alert show];
        [alert release];
    }
    
   
    
}

// 清除缓存方法
- (void)tapSetAction:(UITapGestureRecognizer *)tap
{
    CGFloat cache = [[SDImageCache sharedImageCache] checkTmpSize];
    [[SDImageCache sharedImageCache] clearDisk];
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSString *docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    NSArray *fileList = [fileManager contentsOfDirectoryAtPath:docPath error:nil];
    NSLog(@"%@", fileList);
    for (NSString *str in fileList) {
        if ([str hasSuffix:@".aa"]) {
            NSString *filePath = [docPath stringByAppendingFormat:@"/%@", str];
            [fileManager removeItemAtPath:filePath error:nil];
        }
    }
    
    NSString *cacheStr = [NSString stringWithFormat:@"您清理了%.2fM内存", cache];
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:cacheStr delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
    [alertView show];
    [alertView release];
}

- (void)switchAction:(UISwitch *)switchs
{
    if (switchs.isOn == NO) {
        
         NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:@"yes", @"key", nil];
        
        [[NSNotificationCenter defaultCenter] postNotificationName:@"night" object:nil userInfo:dic];
        
    }else if (switchs.isOn == YES) {
        
        NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:@"no", @"key", nil];
        
        [[NSNotificationCenter defaultCenter] postNotificationName:@"night" object:nil userInfo:dic];
    }
    
}
// 分享按钮
- (void)leftBarAction:(UIBarButtonItem *)left
{
    AppDelegate *myDelegate =(AppDelegate*)[[UIApplication sharedApplication] delegate];
    
    WBAuthorizeRequest *authRequest = [WBAuthorizeRequest request];
    authRequest.redirectURI = REDIRECTURI;
    authRequest.scope = @"all";
    
    WBSendMessageToWeiboRequest *request = [WBSendMessageToWeiboRequest requestWithMessage:[self messageToShare] authInfo:authRequest access_token:myDelegate.wbtoken];
    request.userInfo = @{@"ShareMessageFrom": @"SendMessageToWeiboViewController",
                         @"Other_Info_1": [NSNumber numberWithInt:123],
                         @"Other_Info_2": @[@"obj1", @"obj2"],
                         @"Other_Info_3": @{@"key1": @"obj1", @"key2": @"obj2"}};
//        request.shouldOpenWeiboAppInstallPageIfNotInstalled = NO;
    [WeiboSDK sendRequest:request];
}
- (WBMessageObject *)messageToShare
{
    WBMessageObject *message = [WBMessageObject message];
    NSString *str = @"享听  享受世界，享受生活";
    message.text = str;
    WBImageObject *image = [WBImageObject object];
    image.imageData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"开机动画" ofType:@"png"]];
    message.imageObject = image;
    return message;
}

//右侧注销按钮
- (void)barAction:(UIBarButtonItem *)bar
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"是否注销" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    alert.tag = 10000;
    [alert show];
    [alert release];
}

#pragma mark -
#pragma WBHttpRequestDelegate

- (void)request:(WBHttpRequest *)request didFinishLoadingWithResult:(NSString *)result
{
//    NSString *title = nil;
//    UIAlertView *alert = nil;
    
//    title = NSLocalizedString(@"收到网络回调", nil);
//    alert = [[UIAlertView alloc] initWithTitle:title
//                                       message:[NSString stringWithFormat:@"%@",result]
//                                      delegate:nil
//                             cancelButtonTitle:NSLocalizedString(@"确定", nil)
//                             otherButtonTitles:nil];
    
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"注销成功" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
    
    [alert show];
    [alert release];

    
    
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (alertView.tag == 10000) {
        
        if (buttonIndex == 1) {
            
            AppDelegate *myDelegate =(AppDelegate*)[[UIApplication sharedApplication] delegate];
            [WeiboSDK logOutWithToken:myDelegate.wbtoken delegate:self withTag:@"user1"];
            
            UIView *view = (UIView *)[self.view viewWithTag:100];
            UIView *view2 = (UIView *)[self.view viewWithTag:102];
            view.hidden = NO;
            view2.hidden = YES;
            
            self.navigationItem.rightBarButtonItem = nil;
            
            DataBaseHandler *handler = [DataBaseHandler shareInstance];
            
            [handler closeDB];
            
            [[NSNotificationCenter defaultCenter] postNotificationName:@"uid" object:@"YES" userInfo:nil];
            NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
            [userDefault setObject:@"NO" forKey:@"isLogin"];
            [userDefault synchronize];
            self.Judgement = @"NO";
        }

        
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
